<template>
    <div class="container">
        <div class="row mt-5 justify-content-between">
            <div class="col-12 col-md-6">
                <div class="absrtact">
                    <h4>免费领养 喵喵</h4>
                    <h3>需支付固定运费和喵咪保险 <span>650 + 50 = 700</span>(元)</h3>
                    <p>这是一只活泼好动的小猫，名叫小跳。她总是充满好奇心，喜欢探索新环境。小跳特别喜欢追逐玩具和与人互动，非常适合有时间和精力陪伴她的家庭。</p>
                </div>
                <el-form :model="formData" :rules="rules" ref="form" label-width="100px" label-position="top">
                    <h3>领养地址</h3>
                    <el-form-item label="姓名" prop="name">
                        <el-input v-model="formData.name" placeholder="请输入姓名"></el-input>
                    </el-form-item>
                    <el-form-item label="电话" prop="phone">
                        <el-input v-model="formData.phone" placeholder="请输入电话号码"></el-input>
                    </el-form-item>
                    <el-form-item label="省市区">
                        <el-row :gutter="20">
                            <el-col :span="8">
                                <el-select v-model="formData.province" placeholder="----选择省份----" @change="loadCities">
                                    <el-option v-for="(province, index) in allProvinces" :key="index"
                                        :label="province.name" :value="province.name"></el-option>
                                </el-select>
                            </el-col>
                            <el-col :span="8">
                                <el-select v-model="formData.city" placeholder="----选择城市----" @change="loadDistricts">
                                    <el-option v-for="(city, index) in cities" :key="index" :label="city"
                                        :value="city"></el-option>
                                </el-select>
                            </el-col>
                            <el-col :span="8">
                                <el-select v-model="formData.district" placeholder="----选择区县----">
                                    <el-option v-for="(district, index) in districts" :key="index" :label="district"
                                        :value="district"></el-option>
                                </el-select>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    <el-form-item label="详细地址" prop="address">
                        <el-input type="textarea" v-model="formData.address" placeholder="请输入详细地址"></el-input>
                    </el-form-item>
                    <h3 class="mt-3">其他信息</h3>
                    <el-form-item label="备注">
                        <el-input type="textarea" v-model="formData.remark" :rows="4"
                            placeholder="请填写备注信息（可选）"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button class="btn-primary" type="primary" @click="handleSubmit">提交</el-button>
                    </el-form-item>
                </el-form>


            </div>
            <div class="col-12 col-md-5">
                <div class="card">
                    <div class="card-body d-flex flex-columg justify-content-center align-items-center">
                        <img class="img-fulid" src="../../assets/images/contact.png" alt="">
                    </div>
                    <ul class="d-flex flex-column gap-3 mt-5">
                        <li class="d-flex align-items-center gap-4">
                            <div class="icon">
                                <font-awesome-icon :icon="['fas', 'map-marker-alt']" />
                            </div>
                            <p>成都市成华区铁建广场2幢1122</p>
                        </li>
                        <li class="d-flex align-items-center gap-3">
                            <div class="icon">
                                <font-awesome-icon :icon="['fas', 'phone-alt']" />
                            </div>
                            <p>+9 (256) 254 9568</p>
                        </li>
                        <li class="d-flex align-items-center gap-3">
                            <div class="icon">
                                <font-awesome-icon :icon="['fas', 'envelope-open']" />
                            </div>
                            <p>[email protected] info.com</p>
                        </li>
                    </ul>

                    <div class="mt-4 d-flex gap-5 imglist">
                        <img src="../../assets/images/wb.png" alt="">
                        <img src="../../assets/images/wx2.png" alt="">
                        <img src="../../assets/images/qq.png" alt="">
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import provinceList from '../../utils/provinceList.js';
export default {
    name: 'CatAdoptInfo',

    data() {
        // 自定义电话号码验证函数
        const validatePhone = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('请输入电话号码'));
            } else {
                const phonePattern = /^1[3456789]\d{9}$/; // 简单的中国大陆手机号码正则表达式
                if (!phonePattern.test(value)) {
                    return callback(new Error('请输入正确的电话号码'));
                }
                return callback();
            }
        };
        return {
            formData: {
                name: '',  // 姓名
                phone: '', // 电话
                province: '', // 省
                city: '', // 市
                district: '',  // 区
                address: '', // 详细地址
                remark: '' // 备注
            },
            allProvinces: provinceList, // 加载所有省份数据
            cities: [], // 动态填充城市选项
            districts: [], // 动态填充区县选项
            rules: {
                name: [
                    { required: true, message: '请输入姓名', trigger: 'blur' }
                ],
                phone: [
                    { required: true, validator: validatePhone, trigger: 'blur' }
                ],
                address: [
                    { required: true, message: '请输入详细地址', trigger: 'blur' }
                ]
            },
        }
    },
    methods: {
        loadCities(province) {
            console.log(province);
            if (province) {
                const selectedProvince = this.allProvinces.find(p => p.name === province);
                if (selectedProvince) {
                    this.cities = selectedProvince.cityList.map(city => city.name);
                    this.districts = [];
                    this.formData.city = '';
                    this.formData.district = '';
                } else {
                    this.cities = [];
                    this.districts = [];
                    this.formData.city = '';
                    this.formData.district = '';
                }
            }
        },
        loadDistricts(city) {
            if (city && this.formData.province) {
                const selectedProvince = this.allProvinces.find(p => p.name === this.formData.province);
                if (selectedProvince) {
                    const selectedCity = selectedProvince.cityList.find(c => c.name === city);
                    if (selectedCity) {
                        this.districts = selectedCity.areaList;
                        this.formData.district = '';
                    } else {
                        this.districts = [];
                        this.formData.district = '';
                    }
                }
            } else {
                this.districts = [];
                this.formData.district = '';
            }
        },

        handleSubmit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.$message({
                        message: '支付成功',
                        type: 'success'
                    });
                    // console.log(this.formData);
                    // console.log(this.selectedPaymentMethod);
                    this.$router.push({
                        name: 'home',
                    });
                } else {
                    console.log(this.selectedPaymentMethod);
                    this.$message.error('请检查并填写完整信息');
                    return false;
                }
            });
        }
    }
}
</script>

<style scoped>
p{
    margin: 0;
}
.absrtact h4 {
    font-size: 32px;
    line-height: 1;
    font-weight: bold;
    margin-bottom: 1rem;
}

.absrtact h3 {
    font-family: 'Nunito', sans-serif;
    color: #0a303a;
    margin-top: 0px;
    font-style: normal;
    font-weight: bolder;
    text-transform: inherit;
    margin-bottom: 1.5rem;
}

.absrtact p {
    font-size: 14px;
    margin-bottom: 30px;
    letter-spacing: .4px;
    font-weight: 400;
    line-height: 28px;
    color: #676666;
    text-indent: 2rem;
}

.absrtact span {
    color: rgba(240, 67, 54, 1)
}

:deep(.el-form--label-top .el-form-item__label) {
    padding: 0px;
    font-size: 16px;
    font-weight: bold;
    color: rgba(10,48,58,.9);
}

:deep(.el-form-item) {
    margin-bottom: 12px;
}

:deep(.el-input__inner) {
    height: 50px;
    border-color: rgba(153, 153, 153, .6);
    border-radius: 4px;
    background-color: rgba(245,242,235,1);
    border: 0;
}

:deep(.el-input__inner::placeholder) {
    color: rgba(121,102,102,1);
}

:deep(.el-textarea__inner) {
    /* height: 45px; */
    border-color: rgba(153, 153, 153, .6);
    border-radius: 4px;
    background-color: rgba(245,242,235,1);
    border: 0;
}
:deep(.el-textarea__inner::placeholder) {
    color: rgba(121,102,102,1);
}

.card {
    padding: 38px 55px;
    border: 0;
    background-color: rgba(245,242,235,1);
}
.card-body{
    padding: 0;
}
.card .icon{
    width: 45px;
    height: 45px;
    border-radius:50%;
    background-color: white;
    text-align: center;
    line-height: 45px;
}
.card .icon svg{
    color: red;
}
.card p{
    font-size: 16px;
    line-height: 2;
    color: #696969;
}
.card .imglist{
    padding-left: 32px;
}

.btn-primary{
    user-select: none;
    background: #f04336 none repeat scroll 0 0;
    border: medium none;
    border-radius: 3px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0;
    line-height: 1;
    padding: 17px 50px;
    text-align: center;
    text-transform: capitalize;
    touch-action: manipulation;
    transition: all 0.3s ease 0s;
    vertical-align: middle;
    white-space: nowrap;
    font-family: 'Nunito', sans-serif;
    position: relative;
    margin-top: 1rem;
    margin-bottom: 2rem;
    letter-spacing: .5rem;
}
</style>